<template>
  <div>
    <!-- 头部 -->
    <div class="header">
      <mt-header fixed :title="this.header_title">
        <span slot="left" @click="back" v-show="flag">
          <mt-button icon="back"></mt-button>
        </span>
      </mt-header>
    </div>

    <!-- 中部 -->
    <div class="content">
      <transition>
        <router-view  @getTitle="showTitle" @checkin="login"></router-view>
      </transition>
    </div>

    <!-- 底部 -->
    <div class="footer">
      <nav class="mui-bar mui-bar-tab">
        <router-link class="mui-tab-item" to="/home">
          <span class="mui-icon mui-icon-home"></span>
          <span class="mui-tab-label">首页</span>
        </router-link>
        <router-link class="mui-tab-item" to="/message">
          <span class="mui-icon mui-icon-email">
            <span class="mui-badge">1</span>
          </span>
          <span class="mui-tab-label">消息</span>
        </router-link>
        <router-link class="mui-tab-item" to="/cart">
          <span class="mui-icon mui-icon-extra mui-icon-extra-cart">
            <span class="mui-badge">{{ $store.getters.getTotalNum}}</span>
          </span>
          <span class="mui-tab-label">购物车</span>
        </router-link>
        <router-link class="mui-tab-item" to="/member">
          <span class="mui-icon mui-icon-person"></span>
          <span class="mui-tab-label">我的</span>
        </router-link>
      </nav>
    </div>
  </div>
</template>


<script>
import mui from "./lib/mui/js/mui.min.js";
export default {
  data() {
    return {
      flag: false,
      // 字符串一定要加“”
      header_title : "首页",
      timerId:""
    };
  },
  created() {
    this.flag = this.$route.path === "/home" ? false : true;
  },
  mounted() {
    mui.init();
  },
  methods: {
    back() {
      this.$router.go(-1);
    },
    showTitle(title){
      this.header_title = title;
    },
    login(){
      clearTimeout(this.timerId);
      if(!localStorage.getItem("login")){
        mui.alert("请先登录",(message)=>{
          if(message.index==0){
            this.$router.push("/member/login")
          }
        })
        this.timerId = setTimeout(()=>{
          this.$router.push("/member/login")
        },100)
      }
    },

  },
  watch : {
      "$route.path" : function(newVal){
        this.flag = newVal == '/home' ? false : true;
      }
  }
};
</script>

<style lang="scss" scoped>
$baseColor: #26a2ff;
* {
  touch-action: pan-x;
}
body {
  background: #eee;
}
.mint-header {
  z-index: 99;
  font-size: 16px;
}
.content {
  padding-top: 40px;
  padding-bottom: 50px;
  overflow-x: hidden;
  font-size: 14px;
}

.v-enter {
  opacity: 0;
  transform: translateX(100%);
}
.v-leave-to {
  opacity: 0;
  transform: translateX(-100%);
  position: absolute;
}
.v-enter-active,
.v-leave-active {
  transition: all 0.5s ease;
}
.footer {
  .mui-bar {
    box-shadow: 0 0 1px rgba(0, 0, 0, 0.05);
  }
}
</style>

